﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AviDemo
{
    public partial class CreateAviForm : Form
    {
        private AviHandler handler = null;
        private string path = "";

        public CreateAviForm(AviHandler handler, string path)
        {
            InitializeComponent();
            this.handler = handler;
            this.path = path;
            if (path.Equals(""))
                button2.Enabled = false;
            else
                button2.Enabled = true;
        }

        private void btnSelectFiles_Click(object sender, EventArgs e)
        {
            if (fileMultiDialog.ShowDialog() == DialogResult.OK)
            {
                lbImageFiles.Items.AddRange(fileMultiDialog.FileNames);
                btnWriteCompress.Enabled = fileMultiDialog.FileNames.Length > 0;
            }
        }

        private void btnClearImageFiles_Click(object sender, EventArgs e)
        {
            lbImageFiles.Items.Clear();
        }

        private void btnWrite_Click(object sender, EventArgs e)
        {
            FrameRateForm dlg = new FrameRateForm();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                List<string> list = new List<string>();
                foreach (Object o in lbImageFiles.Items)
                    list.Add(o as string);
                handler.BuildNewFromImages(dlg.DestPath, list, dlg.Rate, false);
            }
        }

        private void btnWriteCompress_Click(object sender, EventArgs e)
        {
            FrameRateForm dlg = new FrameRateForm();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                List<string> list = new List<string>();
                foreach (Object o in lbImageFiles.Items)
                    list.Add(o as string);
                handler.BuildNewFromImages(dlg.DestPath, list, dlg.Rate, true);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            fileSaveDlg.Filter = "Avi Files|*.avi";
            if (fileSaveDlg.ShowDialog() == DialogResult.OK)
            {
                List<string> list = new List<string>();
                foreach (Object o in lbImageFiles.Items)
                    list.Add(o as string);
                handler.AppendImageToExist(path, fileSaveDlg.FileName, list);
            }
        }
    }
}
